package com.su.sweet.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.su.sweet.model.SRole;
import com.su.sweet.mapper.SRoleMapper;
import com.su.sweet.service.ISRoleService;
import org.apache.ibatis.solon.annotation.Db;
import org.noear.solon.annotation.Component;

import javax.management.relation.Role;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author su
 * @since 2025-01-02
 */
@Component
public class SRoleServiceImpl implements ISRoleService {
    @Db
    private SRoleMapper roleMapper;


    @Override
    public Map<String, Object> list(Integer pageNo, Integer pageSize) {
        Map<String, Object> map = new HashMap<>();
        Page<SRole> rolePage = roleMapper.selectPage(new Page<>(pageNo, pageSize), new QueryWrapper<SRole>().orderByAsc("role_sort"));
        map.put("list", rolePage.getRecords());
        map.put("total", rolePage.getTotal());
        return map;
    }

    @Override
    public Integer insert(SRole role) {
        return roleMapper.insert(role);
    }

    @Override
    public Integer update(SRole role) {
        return roleMapper.updateById(role);
    }

    @Override
    public Integer delete(Integer id) {
        return roleMapper.deleteById(id);
    }

    @Override
    public List<SRole> allRole() {
        return roleMapper.selectList(null);
    }
}
